#include <iostream>
#include "ostream"
#include "string"


class Person12 {

public:
    int *age;

public:
    Person12(int age) {
        this->age = new int(age);
    }

    // 重载 赋值运算符
    Person12 &operator=(Person12 &p) {
        if (age != NULL) {
            delete age;
            age = NULL;
        }
        this->age = new int(*p.age);

        return *this;
    }

    virtual ~Person12() {
        if (age != NULL) {
            delete age;
            age = NULL;
        }
    }
};


void test01() {
    Person12 p1(18);
    Person12 p2(20);
    Person12 p3(30);

    p2 = p1 = p3; // 赋值操作

    std::cout << *p1.age << std::endl;
    std::cout << *p2.age << std::endl;
    std::cout << *p3.age << std::endl;
}


int main() {
    test01();
    return 0;
}

